package it.webrules.deploymanager.webapp.auth;

import java.io.Serializable;
import java.security.Principal;

/**
 * 
 * Represent the user of this demo application
 * 
 * @author dometec
 *
 */
public class DMPrincipal implements Principal, Serializable {

	private static final long serialVersionUID = 1L;

	private String username;
	private String password;
	private String[] roles;

	public DMPrincipal(String username, String password, String[] roles) {
		this.username = username;
		this.password = password;
		this.roles = roles;
	}

	public DMPrincipal(String username, String password, String role) {
		this(username, password, new String[] { role });
	}

	public String getPassword() {
		return password;
	}

	@Override
	public String getName() {
		return username;
	}

	public boolean hasRole(String role) {

		if ("*".equals(role))
			return true;

		if (role == null)

			return false;

		for (String i : roles) {
			if (role.equals(i))
				return true;
		}

		return false;
	}

	public String[] getRoles() {
		return roles;
	}

}
